<template>
	<view>
		<view class="news_item" @click="navigator(item.id)" v-for="item in newsList" v-bind:key="item.id">
			<image v-bind:src="item.img_url"></image>
			<view class="right">
				<view class="tit">
					{{item.title}}
				</view>
				<view class="info">
					<text>发表时间：{{item.add_time | formatDate}}</text>
					<text>浏览次数：{{item.click}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props:['newsList'],
		filters:{
			formatDate(date){
				const nDate = new Date(date)
				// 处理年份
				const year = nData.getFullYear()
				// 处理月份
				const month = nData.getMonth().toString().padStart(2,0) 
				// 处理日期
				const day = nData.getDay().toString().padStart(2,0)
				return year + '-' + month + '-' + day
			}
		},
		methods:{
			navigator(id){
				this.$emit('itemClick',id)
			}
		}
	}
</script>

<style lang="scss">
	.news{
		.news_item{
			display: flex;
			padding: 10rpx 20rpx;
			border-bottom: 1px solid $shop-color;
			image{
				min-width: 200rpx;
				min-height: 200rpx;
			}
			.right{
				margin-left: 15rpx;
				display: flex;
				flex-direction : column;
				justify-content: space-between;
				.tit{
					font-size: 30rpx;
				}
				.info{
					font-size: 24rpx;
					text : nth-child(2){
						margin-left: 30rpx;
					}
				}
			}
		}
	}
</style>